package com.company.kotlinlearn.viewmodel

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Observer
import com.company.kotlinlearn.R
import com.company.kotlinlearn.databinding.FragmentLeftBinding
import com.company.kotlinlearn.databinding.FragmentRightBinding

class RightFragment : Fragment() {
    // TODO: Rename and change types of parameters

    private val viewModel: DataViewModel by activityViewModels()
    private lateinit var viewBinding: FragmentRightBinding

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
         viewBinding = FragmentRightBinding.inflate(inflater, container, false)
        // Inflate the layout for this fragment
//        return inflater.inflate(R.layout.fragment_right, container, false)
        return viewBinding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
//        val textView = view.findViewById<TextView>(R.id.right_text)
        activity?.let { it ->
            viewModel.getDataLiveData().observe(it, Observer {
//                textView.text = it.toString()
                viewBinding.rightText.text = it.toString()
            })
        }
    }
}